package com.camel;

import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultExchange;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class DynamicRouteAdditionTest {

	public static void main(String[] args) throws Exception {
		ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext("camel/dynamic-context.xml");
		CamelContext context = appContext.getBean(CamelContext.class);
		System.out.println("adding route");
		context.addRoutes(new RouteBuilder() {
			@Override
			public void configure() throws Exception {
				from("file://target/out?delay=5000").id("dynamicRoute").to("file:///dev?fileName=null");
			}
		});
		
		Thread.sleep(1000);
		
		Exchange exchange1 = new DefaultExchange(context);
		exchange1.getIn().setBody("Input");
		context.createProducerTemplate().send("direct:input", exchange1);
		
		Thread.sleep(100 * 1000);
		
	}
}
